package com.bruce.main.viewadpter.calendar;

import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;

import androidx.databinding.BindingAdapter;

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;

import java.util.List;

import me.goldze.mvvmhabit.binding.command.BindingCommand;

/**
 * Created by goldze on 2017/6/18.
 */
public class ViewAdapter {
    @BindingAdapter(value = {"onCalendarSelect","OnYearChange","OnMonthChange","OnWeekChange"}, requireAll = false)
    public static void setCalendarData(CalendarView calendarView, BindingCommand<Calendar> onCalendarSelect, BindingCommand<Integer> onYearChange,
                                BindingCommand<Calendar> onMonthChange,  BindingCommand<List<Calendar>> onWeekChange) {
        if (null!=onCalendarSelect) {
            calendarView.setOnCalendarSelectListener(new CalendarView.OnCalendarSelectListener() {
                @Override
                public void onCalendarOutOfRange(Calendar calendar) {

                }

                @Override
                public void onCalendarSelect(Calendar calendar, boolean isClick) {
                    onCalendarSelect.execute(calendar);
                }
            });
        }
        if (null!=onYearChange) {
            calendarView.setOnYearChangeListener(new CalendarView.OnYearChangeListener() {
                @Override
                public void onYearChange(int year) {
                    onYearChange.execute(year);
                }
            });
        }
        if (null!=onMonthChange) {
            calendarView.setOnMonthChangeListener(new CalendarView.OnMonthChangeListener() {
                @Override
                public void onMonthChange(int year, int month) {
                    Log.e("onMonthChange", "  -- " + year + "  --  " + month);
                    onMonthChange.execute(calendarView.getSelectedCalendar());
                }
            });
        }
        if (null!=onWeekChange) {
            calendarView.setOnWeekChangeListener(new CalendarView.OnWeekChangeListener() {
                @Override
                public void onWeekChange(List<Calendar> weekCalendars) {
                    onWeekChange.execute(weekCalendars);
                }
            });
        }
    }
}
